<?php class company extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function insert(){
       $this->name = $_POST['name'];
       $this->address = $_POST['address'];
       $this->contacter = $_POST['contacter'];
       $this->phone = $_POST['phone'];
       $this->createtime = time();
       $re = $this->auth($_POST['name']);
       if($re==0){
         $result = $this->db->insert('company',$this);
       }else{
         $result = true;
       }
       return $result;
    }
    
    
    function auth($name){
    	$this->db->where(array('name'=>trim($name)));
    	$this->db->from('company');
        $result = $this->db->count_all_results(); 
        return $result;
    }
    
    function select($id,$num="",$offset=""){
       $this->db->limit($num,$offset);	
       if($id!=""){
       	  $this->db->where(array('company_id'=>$id));
       }
       $query = $this->db->get('company');
       $result = $query->result(); 
       return $result;
    }
    
    function update($id){
       $this->name = $_POST['name'];
       $this->address = $_POST['address'];
       $this->contacter = $_POST['contacter'];
       $this->phone = $_POST['phone'];
       $result = $this->db->update('company',$this,array('company_id'=>$id));
       return $result;
    }
    
    function del($id){
       $result = $this->db->delete('company',array('company_id'=>$id));
       return $result;
    }
}